ef7c39
@@ -545,22 +545,26 @@
public static String getKeywords(Set<String> excludes) {
 
   public static RelNode parseQuery(HiveConf conf, String viewQuery)
       throws SemanticException, IOException, ParseException {
-    return getAnalyzer(conf).genLogicalPlan(parse(viewQuery));
+    final Context ctx = new Context(conf);
+    ctx.setIsLoadingMaterializedView(true);
+    final ASTNode ast = parse(viewQuery, ctx);
+    final CalcitePlanner analyzer = getAnalyzer(conf, ctx);
+    return analyzer.genLogicalPlan(ast);
   }
 
   public static List<FieldSchema> parseQueryAndGetSchema(HiveConf conf, String viewQuery)
       throws SemanticException, IOException, ParseException {
-    final CalcitePlanner analyzer = getAnalyzer(conf);
-    analyzer.genLogicalPlan(parse(viewQuery));
+    final Context ctx = new Context(conf);
+    ctx.setIsLoadingMaterializedView(true);
+    final ASTNode ast = parse(viewQuery, ctx);
+    final CalcitePlanner analyzer = getAnalyzer(conf, ctx);
+    analyzer.genLogicalPlan(ast);
     return analyzer.getResultSchema();
   }
 
-  private static CalcitePlanner getAnalyzer(HiveConf conf) throws SemanticException, IOException {
-    final QueryState qs =
-        new QueryState.Builder().withHiveConf(conf).build();
-    CalcitePlanner analyzer = new CalcitePlanner(qs);
-    Context ctx = new Context(conf);
-    ctx.setIsLoadingMaterializedView(true);
+  private static CalcitePlanner getAnalyzer(HiveConf conf, Context ctx) throws SemanticException {
+    final QueryState qs = new QueryState.Builder().withHiveConf(conf).build();
+    final CalcitePlanner analyzer = new CalcitePlanner(qs);
     analyzer.initCtx(ctx);
     analyzer.init(false);
     return analyzer;
